import { http } from '@/utils/luch-request/index.js'
import {apiObj} from '@/utils/api-obj.js';
import myconfig  from "@/config/index";
//console.log(myconfig)
const commonApi = {
	/**
	 * 检测是否是正确的人脸头像，比对人脸质量
	 * imageType 为1时，上传本次资源地址
	 * imageType 为3时，上传url地址
	 */
	checkUserFace:async (imageType,file) =>{
		//console.log(file)
		if(file == '' || !file)
		{
			apiObj.msg('请上传人脸照片');
			return false;
		}
		return new Promise((resolve, reject) =>  {
			apiObj.loadingMsg('正在检测人脸头像');
			if(imageType == 1)
			{
				//上传本次图片地址
				http.upload('uniapi/system/baidubceFace',{
					filePath: file,
					name: 'file_name',
					formData: {
						image_type:1
					},
				}).then(res=>{
					if(res.code == 1){
						resolve(res.data);
					}else{
						apiObj.msg(res.msg);
						resolve(false);
					}
				}).catch(res=>{
					apiObj.msg('检测人脸失败');
					resolve(false);
				})
			}else if (imageType == 2)
			{
				//上传本次图片地址
				http.post('uniapi/system/baidubceFace',{file_base64:file,image_type:2}).then(res=>{
					if(res.code == 1){
						resolve(res.data);
					}else{
						apiObj.msg(res.msg);
						resolve(false);
					}
				}).catch(res=>{
					apiObj.msg('检测人脸失败');
					resolve(false);
				})
			}else{
				//上传网络地址
				http.post('uniapi/system/baidubceFace',{file_url:file,image_type:3}).then(res=>{
					if(res.code == 1){
						resolve(res.data);
					}else{
						apiObj.msg(res.msg);
						resolve(false);
					}
				}).catch(res=>{
					apiObj.msg('检测人脸失败');
					resolve(false);
				})
			}
		})
	},
};
/**
 * 获取教师年级班级范围
 */
export {commonApi}